package com.geotmt.billingcenter.modules.statis.controller;

import com.geotmt.billingcenter.common.result.ResponseResult;
import com.geotmt.billingcenter.common.vo.cost.CostStatisVo;
import com.geotmt.billingcenter.common.vo.params.PageOrgFilter;
import com.geotmt.billingcenter.common.vo.params.ParamsCost;
import com.geotmt.billingcenter.modules.statis.service.CostStatisService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description 类描述
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/4/1 17:19
 * @Version     v1
 **/
@Api(value = "成本统计接口",tags = "成本统计接口")
@RestController
@RequestMapping(value = "/bc/costStatis")
public class CostStatisController extends PageOrgFilter {

    private static final Logger logger = LoggerFactory.getLogger(CostStatisController.class);

    @Resource
    private CostStatisService costStatisService;

    /**
     * 成本统计
     * @return
     */
    @ApiOperation(value = "成本统计")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public ResponseResult costStatis(@RequestBody ParamsCost obj){
        logger.info("成本统计,ParamsConsume:{}",obj);
        PageInfo<CostStatisVo> page;
        try{
            this.filterPage(obj,"t1.day_flag desc");
            page = new PageInfo<>(costStatisService.costStatisList(obj));
            CostStatisVo costStatisVo = costStatisService.costStatisTotal(obj);
            System.out.println(costStatisVo);
        }catch (Exception e) {
            e.printStackTrace();
            logger.error("成本统计,Exception:",e);
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",page,true);
    }
}
